package com.coda.controller;

import com.coda.adminVo.apartment.ApartmentDetailVo;
import com.coda.adminVo.apartment.ApartmentItemVo;
import com.coda.adminVo.apartment.ApartmentQueryVo;
import com.coda.adminVo.apartment.ApartmentSubmitVo;
import com.coda.entity.ApartmentInfo;
import com.coda.result.PageResult;
import com.coda.result.Result;
import com.coda.service.ApartmentService;
import com.github.pagehelper.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/apartment")
@Api(tags = "公寓管理")
public class ApartmentController {

    @Autowired
    private ApartmentService apartmentService;

    /**
     * 保存或更新公寓信息
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperation(value = "保存或更新用户信息")
    public Result saveOrUpdate(@RequestBody ApartmentSubmitVo apartmentSubmitVo) {
        apartmentService.saveOrUpdate(apartmentSubmitVo);
        return Result.ok();
    }
    /**
     * 条件分页查询公寓列表
     */
    @GetMapping("/pageItem")
    @ApiOperation("条件分页查询公寓列表")
    public Result<PageResult> page(@RequestParam("current") Integer current,
                                   @RequestParam("size") Integer size,
                                   ApartmentQueryVo apartmentQueryVo){
        PageResult pageResult = apartmentService.pagelist(current,size,apartmentQueryVo);
        return Result.ok(pageResult);
    }
    /**
     * 根据id获取公寓详细信息
     */
    @GetMapping("/getDetailById")
    @ApiOperation("根据ID获取公寓详细信息")
    public Result<ApartmentDetailVo> getApartmentDetailById(Long id){
        ApartmentDetailVo apartmentDetailVo = apartmentService.getDetailById(id);
        return Result.ok(apartmentDetailVo);
    }
    /**
     * 根据id删除公寓信息
     */
    @DeleteMapping("/removeById")
    @ApiOperation("根据id删除公寓信息")
    public Result removeById(Long id){
        apartmentService.removeById(id);
        return Result.ok();
    }
    /**
     * 根据id修改房间公寓发布状态
     */
    @PostMapping("/updateReleaseStatusById")
    @ApiOperation("根据id修改房间公寓发布状态")
    public Result updateStatus(Long id,Integer status){
        apartmentService.updateStatus(id,status);
        return Result.ok();
    }
    /**
     * 根据县区id查询公寓信息列表
     */
    @GetMapping("/listInfoByDistrictId")
    @ApiOperation("根据县区id查询公寓信息列表")
    public Result<List<ApartmentInfo>> listInfoByDistrictId(Long id){
        List<ApartmentInfo> apartmentInfo = apartmentService.listInfoByDistrictId(id);
        return Result.ok(apartmentInfo);
    }
}
